#include "gtest/gtest.h"
#include "gx_sort.h"

class array:public ::testing::Test
{
	protected:
		virtual void SetUp()
		{
			srand(time(NULL));
			size = rand()%1000;
			a = (int*)malloc(size*sizeof(int));
			if(a == NULL)
			{
				printf("No Memory\n");
				return;
			}
			for(int i=0;i<size;i++)
				a[i] = rand()%1000;
		}

		virtual void TearDown()
		{
			if(a != NULL)
				free(a);
		}
		int *a;
		int size;
};

int sort_compare(const void *a,const void *b)
{
	int * tmp1 = (int *)a;
	int *tmp2 =(int *)b;
	return *tmp1-*tmp2;
}

TEST_F(array,sample)
{
	
	ASSERT_NE((int*)NULL,a);

	qqsort(a,size,sizeof(int),sort_compare);

	for(int i=0;i<size-1;i++)
	{
		ASSERT_LE(a[i],a[i+1]);
	}
}

TEST(moreassertion,sucess)
{
	SUCCEED();
	//ASSERT_EQ(1,0);
}

TEST(moreassertion,failure)
{
	//FAIL();
	//ADD_FAILURE();
	//ASSERT_EQ(1,1);
//	ADD_FAILURE_AT("/home/gaoxin..",123);
}

bool test_proced(int a,int b)
{
	if(a < b)
	{
		int tmp =a;
		a=b;
		b=tmp;
	}
	if(a%b == 0)
		return true;
	else
		return false;
}

TEST(moreassertion,proced)
{
	ASSERT_PRED2(test_proced,4,2);
//	ASSERT_PRED2(test_proced,5,3);
}

::testing::AssertionResult IsEven(int a)
{
	if(a%2 == 0)
		return ::testing::AssertionSuccess()<<"right";
	else
		return ::testing::AssertionFailure()<<"wrong";
}

TEST(moreassertion,assertionresult)
{
	ASSERT_TRUE(IsEven(10));
	//ASSERT_TRUE(IsEven(3));
	ASSERT_FALSE(IsEven(7));
	//ASSERT_FALSE(IsEven(8));
}
